/* * @(#)LoginManagerImpl.java	 2012-9-18 * * Copyright 2004-2012 Liuzhongnan.  * All rights reserved. *  * LiuZhongnan 81595157@126.com PROPRIETARY/CONFIDENTIAL. */package com.bieyang.anjia.net;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import org.apache.http.HttpResponse;import org.apache.http.NameValuePair;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.HttpClient;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.HttpPost;import org.apache.http.message.BasicNameValuePair;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import android.content.Context;import android.os.AsyncTask;import android.os.Handler;import android.os.Looper;import android.os.Message;import android.util.Log;import cn.jpush.android.api.JPushInterface;import com.alibaba.fastjson.JSON;import com.bieyang.anjia.R;import com.bieyang.anjia.module.Deviceinfo;import com.bieyang.anjia.module.Device;import com.bieyang.anjia.module.FileModel;import com.bieyang.anjia.module.HelpInfo;import com.bieyang.anjia.module.NewsInfo;import com.bieyang.anjia.module.User;import com.bieyang.anjia.net.QiniuUrl.ResultData;import com.bieyang.anjia.sqlitedatabase.AnjiaSQLiteOpenHelper;import com.bieyang.anjia.sqlitedatabase.SqliteOperation;import com.bieyang.anjia.ui.activity.AcLogin;import com.bieyang.anjia.ui.activity.AcMain;import com.bieyang.anjia.ui.activity.App;import com.bieyang.anjia.ui.activity.PubService;import com.bieyang.anjia.utils.ApplicationUtils;import com.bieyang.anjia.utils.Constants;import com.bieyang.anjia.utils.HttpClientFactory;import com.bieyang.anjia.utils.SharedPrefsUtil;import com.bieyang.anjia.utils.SubUtils;import com.bieyang.anjia.utils.Util;import com.google.gson.Gson;public class NetManager {	public static boolean refreshDev;	/**	 * 设备列表	 */	public static List<Deviceinfo> deviceList = new ArrayList<Deviceinfo>();	/**	 * 帮助列表	 */	public static List<HelpInfo> helpList = new ArrayList<HelpInfo>();	/**	 * 在线状态列表	 */	public static HashMap<String, String> subOnLineMap = new HashMap<String, String>();	public interface ICallBack {		/** 登录成功回调接口 */		public void onSuccess();		/** 登录失败回调接口 */		public void onFailed(String error);	}	/**	 * login	 * */	public void login(final Context con, final User user, final Handler handler) {		final String url = Constants.SERVER_URL + Constants.ACTION_LOGIN;		Log.d("url", url);		new Thread() {			public void run() {				try {					HttpClient httpClient = HttpClientFactory.getFactory()							.getHttpClient();					HttpPost httpPost = new HttpPost(url);					List<NameValuePair> formparams = new ArrayList<NameValuePair>();					formparams.add(new BasicNameValuePair("loginId", user							.getCardNo()));					formparams.add(new BasicNameValuePair("password", user							.getPassword()));					formparams.add(new BasicNameValuePair("uuid", user							.getUuid()));					formparams.add(new BasicNameValuePair("clientId",							JPushInterface.getRegistrationID(App.mContext)));					Log.d("Login",							"clientId="									+ JPushInterface											.getRegistrationID(App.mContext));					formparams.add(new BasicNameValuePair("type", user							.getType().getCode()));					Log.d("jpushID", SharedPrefsUtil.getStringValue(con,							AcLogin.REGISTRATION_ID, ""));					Log.d("type", user.getType().getCode());					UrlEncodedFormEntity entity;					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					// ----------------------------					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonStringLogin", jsonString);					System.out.println("jsonStringLogin==" + jsonString);					JSONObject dataJson;					dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					switch (status) {					case 0:						PubService.beat = new JSONObject(								dataJson.getString("data")).getInt("beat");						String auth = new JSONObject(dataJson.getString("data"))								.getString("auth");						String memberId = new JSONObject(auth)								.getString("memberId");						String deviceName = new JSONObject(auth)								.getString("deviceName");						SharedPrefsUtil.putValue(App.mContext, "memberId",								memberId);						SharedPrefsUtil.putValue(App.mContext, "deviceName",								deviceName);						Log.d("ok", "ok");						if (null != handler)							handler.sendEmptyMessage(Constants.LOGIN_SUCESS);						break;					case 4:// no user						if (null != handler)							handler.sendEmptyMessage(Constants.LOGIN_NO_USER);						break;					case 5:// wrong password						if (null != handler)							handler.sendEmptyMessage(Constants.LOGIN_WRONG_PASSWORD);						break;					case 9:// 该忠机已被其他账号绑定						if (null != handler)							handler.sendEmptyMessage(Constants.LOGIN_SUB_NO);						break;					default:						if (null != handler)							handler.sendEmptyMessage(Constants.LOGIN_FAIL);						break;					}				} catch (Exception e) {					Log.e("LoginNRegisterActivity.login()", e.getMessage() + "");					if (null != handler)						handler.sendEmptyMessage(Constants.LOGIN_FAIL);				}			};		}.start();	}	/**	 * 保持心跳,登录失效后重新登录	 * 	 * */	public void loginEx(final Handler handler) {		final String url = Constants.SERVER_URL + Constants.ACTION_LOGIN;		new Thread(new Runnable() {			@Override			public void run() {				try {					HttpClient httpClient = HttpClientFactory.getFactory()							.getHttpClient();					HttpPost httpPost = new HttpPost(url);					Log.d("url02", url);					List<NameValuePair> formparams = new ArrayList<NameValuePair>();					formparams.add(new BasicNameValuePair("loginId",							SharedPrefsUtil.getStringValue(App.mContext,									"phone", "")));					formparams.add(new BasicNameValuePair("password",							SharedPrefsUtil.getStringValue(App.mContext,									"password", "")));					formparams.add(new BasicNameValuePair("uuid", SubUtils							.getUuid(App.mContext)));					formparams.add(new BasicNameValuePair("clientId",							JPushInterface.getRegistrationID(App.mContext)));					formparams.add(new BasicNameValuePair("type",							SharedPrefsUtil.getStringValue(App.mContext,									"loginType", "M")));					UrlEncodedFormEntity entity;					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					if (0 == status) {						handler.sendEmptyMessage(Constants.LOGIN_SUCESS);					} else {						handler.sendEmptyMessage(Constants.LOGIN_FAIL);					}				} catch (Exception e) {					Log.e("LoginNRegisterActivity.login()", e.getMessage() + "");					handler.sendEmptyMessage(Constants.LOGIN_FAIL);				}			}		}).start();	}	/**	 * login out	 * */	public void logout(final Context con, final Handler handler) {		final String url = Constants.SERVER_URL + Constants.ACTION_LOGOUT;		new Thread() {			public void run() {				try {					HttpClient httpClient = HttpClientFactory.getFactory()							.getHttpClient();					HttpPost httpPost = new HttpPost(url);					Log.d("dev:", SharedPrefsUtil.getStringValue(App.mContext,							"cookie", ""));					httpPost.setHeader("Cookie", SharedPrefsUtil							.getStringValue(App.mContext, "cookie", ""));					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					if (0 == status || 7 == status) {						Log.d("ok", "ok");						if (null != deviceList) {							deviceList.clear();						}						subOnLineMap.clear();						handler.sendEmptyMessage(Constants.LOGOUT_SUCESS);					} else {						Log.d("fail", "fail");						handler.sendEmptyMessage(Constants.LOGOUT_FAIL);					}				} catch (Exception e) {					Log.e("LoginNRegisterActivity.login()", e.getMessage() + "");					handler.sendEmptyMessage(Constants.LOGOUT_FAIL);				}			};		}.start();	}	/**	 * 注册	 * */	public void register(final String name, final String pass,			final String uuid, final String code, final Handler handler) {		final String url = Constants.SERVER_URL + Constants.ACTION_REGISTER;		new Thread() {			public void run() {				try {					HttpClient httpClient = HttpClientFactory.getFactory()							.getHttpClient();					HttpPost httpPost = new HttpPost(url);					List<NameValuePair> formparams = new ArrayList<NameValuePair>();					formparams.add(new BasicNameValuePair("userName", name));					formparams.add(new BasicNameValuePair("password", pass));					formparams.add(new BasicNameValuePair("uuid", uuid));					formparams.add(new BasicNameValuePair("type", "01"));					formparams.add(new BasicNameValuePair("code", code));					UrlEncodedFormEntity entity;					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					switch (status) {					case 0:						if (null != handler)							handler.sendEmptyMessage(Constants.REGISTER_SUCESS);						break;					case 1:// fail						if (null != handler)							handler.sendEmptyMessage(Constants.REGISTER_FAIL);						break;					case 3:// already exit						if (null != handler)							handler.sendEmptyMessage(Constants.REGISTER_EXIT_USER);						break;					case 10:// already exit						if (null != handler)							handler.sendEmptyMessage(Constants.CODE_ERROR);						break;					default:						break;					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (JSONException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}.start();	}	/**	 * 获取注册验证码	 * */	public void getRegisterCode(final String name, final Handler handler) {		final String url = Constants.SERVER_URL				+ Constants.ACTION_REGISTER_CODE;		new Thread(new Runnable() {			@Override			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("user", name));				formparams.add(new BasicNameValuePair("mobile", name));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					switch (status) {					case 0:						handler.sendEmptyMessage(Constants.CODE_SUCCESS);						break;					default:						handler.sendEmptyMessage(Constants.CODE_FAIL);						break;					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (JSONException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}).start();	}	/**	 * 找回密码验证码	 * */	public void getFindpasswordCode(final String name, final Handler handler) {		final String url = Constants.SERVER_URL				+ Constants.UPDATE_PASSWORD_CODE;		new Thread() {			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("mobile", name));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					if (0 == status) {						handler.sendEmptyMessage(Constants.GET_FINDPASSCODE_OK);					} else {						handler.sendEmptyMessage(Constants.GET_FINDPASSCODE_FAIL);					}				} catch (UnsupportedEncodingException e) {					e.printStackTrace();				} catch (ClientProtocolException e) {					e.printStackTrace();				} catch (IOException e) {					e.printStackTrace();				} catch (JSONException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}.start();	}	/**	 * 下一步，找回密码验证	 * */	public void stepYanzheng(final String code, final Handler handler) {		final String url = Constants.SERVER_URL + Constants.YANZHENG_CODE;		new Thread() {			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("code", code));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					if (0 == status) {						handler.sendEmptyMessage(Constants.YANZHENG_OK);					} else {						handler.sendEmptyMessage(Constants.YANZHENG_FAIL);					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (JSONException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}.start();	}	/**	 * 修改密码	 * */	public void modifyPassword(final String code, final Handler handler) {		final String url = Constants.SERVER_URL + Constants.YANZHENG_CODE;		new Thread() {			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("code", code));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					// Log.d("register-status", status);					if (0 == status) {						handler.sendEmptyMessage(Constants.MODIFY_PASSWORD_OK);						// return R.string.tip_register_ok;					} else {						handler.sendEmptyMessage(Constants.MODIFY_PASSWORD_FAIL);						// return R.string.tip_register_fail;					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (JSONException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}.start();	}	/**	 * 获取忠机列表信息	 * */	public void getDev(final Context con, final Device divice,			final Handler handler) {		if (!ApplicationUtils.netState(con)) {			return;		}		final String url = Constants.SERVER_URL + Constants.ACTION_ALL_SUB;		new Thread() {			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("memberId", divice						.getMemberId()));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					try {						dataJson = new JSONObject(jsonString);						String status = dataJson.get("status").toString();						if (!"0".equals(status)) {							handler.sendEmptyMessage(Constants.GET_DEVICE_FAIL);							return;						}						if (null != deviceList)							deviceList.clear();						// deviceList = new ArrayList<Deviceinfo>();						JSONArray data = dataJson.getJSONArray("data");						int lenth = data.length();						subOnLineMap.clear();						for (int i = 0; i < lenth; i++) {							String id = data.getJSONObject(i).get("id")									.toString();							String uid = data.getJSONObject(i).get("uuid")									.toString();							String devName = data.getJSONObject(i).get("name")									.toString();							String online = data.getJSONObject(i).get("status")									.toString();							if ("ONLINE".equals(subOnLineMap.get(uid))									&& "OFF_LINE".equals(online)) {								SubUtils.showNotification(										App.mContext												.getString(R.string.anxin_offline),										devName												+ App.mContext														.getString(R.string.device_offline),										App.mContext, AcMain.class);							}							subOnLineMap.put(uid, online);							Deviceinfo dev = new Deviceinfo();							dev.id = id;							dev.uuid = uid;							dev.name = devName;							dev.online = online;							if (online.equals("ONLINE")) {								deviceList.add(0, dev); // 获取设备信息列表							} else {								deviceList.add(dev); // 获取设备信息列表							}						}						if (null != deviceList) {							handler.sendEmptyMessage(Constants.GET_DEVICE_SUCESS);						}					} catch (JSONException e) {						// TODO Auto-generated catch block						e.printStackTrace();					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}.start();	}	/**	 * 添加监控机	 * */	public void addDevice(final String uuid, final String phone,			final Handler handler) {		final String url = Constants.SERVER_URL + Constants.ADD_DEVICE;		new Thread() {			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("uuid", uuid));				formparams.add(new BasicNameValuePair("mobile", phone));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					try {						dataJson = new JSONObject(jsonString);						String status = dataJson.get("status").toString();						// JSONArray data = dataJson.getJSONArray("data");						if ("0".equals(status)) {							handler.sendEmptyMessage(Constants.ADD_DEVICE_SUCESS);							// return R.string.success;						} else {							handler.sendEmptyMessage(Constants.ADD_DEVICE_FAIL);							// return R.string.fail;						}					} catch (JSONException e) {						// TODO Auto-generated catch block						e.printStackTrace();					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			};		}.start();	}	/**	 * 删除忠机	 * 	 * */	public void deleteSub(final Device divice, final Handler handler) {		final String url = Constants.SERVER_URL + Constants.ACTION_DELETE_SUB;		new Thread() {			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("id", divice						.getDiviceId()));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					dataJson = new JSONObject(jsonString);					String status = dataJson.get("status").toString();					// JSONArray data = dataJson.getJSONArray("data");					if ("0".equals(status)) {						for (int i = 0; i < deviceList.size(); i++) {							if (divice.getDiviceId().equals(									deviceList.get(i).id)) {								subOnLineMap.put(deviceList.get(i).uuid,										"OFF_LINE");								deviceList.remove(i);								break;							}						}						handler.sendEmptyMessage(Constants.DEVICE_DEL_SUCESS);						// return R.string.success;					} else {						handler.sendEmptyMessage(Constants.DEVICE_DEL_FAIL);						// return R.string.fail;					}				} catch (Exception e) {					e.printStackTrace();					handler.sendEmptyMessage(Constants.DEVICE_DEL_FAIL);				}			};		}.start();	}	/**	 * 忠机名称修改	 * */	public void updateSubName(final Device divice, final Handler handler) {		final String url = Constants.SERVER_URL				+ Constants.ACTION_UPDATE_SUB_NAME;		new Thread(new Runnable() {			@Override			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("id", divice						.getDiviceId()));				formparams.add(new BasicNameValuePair("name", divice						.getDiviceName()));				Log.d("updateSubName", "name=" + divice.getDiviceName());				Log.d("updateSubName", "id=" + divice.getDiviceId());				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					dataJson = new JSONObject(jsonString);					String status = dataJson.get("status").toString();					if ("0".equals(status)) {						for (int i = 0; i < deviceList.size(); i++) {							Deviceinfo info = deviceList.get(i);							if (info.id.equals(divice.getDiviceId())) {								info.name = divice.getDiviceName();								break;							}						}						handler.sendEmptyMessage(Constants.UPDATE_SUBNAME_SUCCESS);					} else {						handler.sendEmptyMessage(Constants.UPDATE_SUBNAME_FAILED);					}				} catch (Exception e) {					e.printStackTrace();					handler.sendEmptyMessage(Constants.UPDATE_SUBNAME_FAILED);				}			}		}).start();	}	/**	 * 意见反馈	 * */	public void backSuggestion(final String memberId, final String content,			final Handler handler) {		final String url = Constants.SERVER_URL + Constants.BACK_SUGGESTION;		new Thread() {			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("memberId", memberId));				formparams.add(new BasicNameValuePair("content", content));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					try {						dataJson = new JSONObject(jsonString);						String status = dataJson.get("status").toString();						// JSONArray data = dataJson.getJSONArray("data");						if ("0".equals(status)) {							handler.sendEmptyMessage(Constants.COMMIT_SUGGESTION_SUCESS);							// return R.string.success;						} else {							handler.sendEmptyMessage(Constants.COMMIT_SUGGESTION_FAIL);							// return R.string.fail;						}					} catch (JSONException e) {						// TODO Auto-generated catch block						e.printStackTrace();					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					e.printStackTrace();				}			};		}.start();	}	/**	 * 报警记录查询	 * */	public void queryAlarm(Context con, final String uuid,			final Handler handler, final String time) {		final String url = Constants.SERVER_URL + Constants.ACTION_QUERY_ALARM;		new Thread(new Runnable() {			@Override			public void run() {				// TODO Auto-generated method stub				Looper.prepare();				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("uuid", uuid));				formparams.add(new BasicNameValuePair("memberId",						SharedPrefsUtil.getStringValue(App.mContext,								"memberId", "0")));				try {					UrlEncodedFormEntity entity;					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					JSONArray data = dataJson.getJSONArray("data");					if (0 == status) {						Message msg = Message.obtain();						msg.what = Constants.QUERY_ALARM_SUCCESS;						msg.obj = data;						handler.sendMessage(msg);					} else {						handler.sendEmptyMessage(Constants.QUERY_ALARM_FAILED);					}				} catch (Exception e) {					// TODO Auto-generated catch block					handler.sendEmptyMessage(Constants.QUERY_ALARM_FAILED);					e.printStackTrace();				}				Looper.loop();			}		}).start();	}	/**	 * 查询报警记录	 * 	 * @param con	 * @param handler	 * @param pageNum	 *            页数	 * @param pageSize	 *            每页显示个数	 */	public void queryAlarmAll(final Context con, final Handler handler,			final String time) {		final String url = Constants.SERVER_URL				+ Constants.ACTION_QUERY_ALARMALL;		new Thread(new Runnable() {			@Override			public void run() {				// TODO Auto-generated method stub				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("memberId",						SharedPrefsUtil.getStringValue(con, "memberId", "0")));				try {					UrlEncodedFormEntity entity;					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					try {						dataJson = new JSONObject(jsonString);						int status = dataJson.getInt("status");						JSONArray data = dataJson.getJSONArray("data");						// SharedPrefsUtil.putValue(App.mContext, "timeRub",						// dataJson.get("timeRub").toString());						if (0 == status) {							Message msg = Message.obtain();							msg.what = Constants.QUERY_ALARM_ALL_SUCCESS;							msg.obj = data;							handler.sendMessage(msg);						} else {							handler.sendEmptyMessage(Constants.QUERY_ALARM_ALL_FAILED);						}					} catch (JSONException e) {						handler.sendEmptyMessage(Constants.QUERY_ALARM_ALL_FAILED);						e.printStackTrace();					}				} catch (Exception e) {					handler.sendEmptyMessage(Constants.QUERY_ALARM_ALL_FAILED);					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}).start();	}	/**	 * 用户基本信息查询	 * */	public void queryUserInfo(final User user, final ICallBack call) {		final String url = Constants.SERVER_URL				+ Constants.ACTION_QUERY_USER_INFO;		new AsyncTask<Void, Void, Integer>() {			@Override			protected Integer doInBackground(Void... params) {				// TODO Auto-generated method stub				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("id", user.getInfoId()));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					try {						dataJson = new JSONObject(jsonString);						String status = dataJson.get("status").toString();						// JSONArray data = dataJson.getJSONArray("data");						if ("0".equals(status)) {							return R.string.success;						} else {							return R.string.fail;						}					} catch (JSONException e) {						// TODO Auto-generated catch block						e.printStackTrace();					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}				return 0;			}			protected void onPostExecute(Integer result) {				switch (result) {				case R.string.success:					if (call != null)						call.onSuccess();					break;				case R.string.fail:					if (call != null)						call.onFailed("fail");					break;				default:					break;				}			};		}.execute();	}	/**	 * 更新用户信息	 * 	 * @param user	 *            用户模型	 * @param call	 */	public void updateUserInfo(final User user, final ICallBack call) {		final String url = Constants.SERVER_URL				+ Constants.ACTION_UPDATE_USER_INFO;		new AsyncTask<Void, Void, Integer>() {			@Override			protected Integer doInBackground(Void... params) {				// TODO Auto-generated method stub				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("id", user.getInfoId()));				formparams.add(new BasicNameValuePair("mark", user.getMark()						+ ""));				switch (user.getMark()) {				case 1:					formparams.add(new BasicNameValuePair("imgHead", user							.getImgHead()));					break;				case 2:					formparams.add(new BasicNameValuePair("nickName", user							.getNickName()));					break;				case 3:					formparams.add(new BasicNameValuePair("mobile", user							.getMobile()));					break;				case 4:					formparams.add(new BasicNameValuePair("level", user							.getLevel()));					break;				case 5:					formparams.add(new BasicNameValuePair("integral", user							.getIntegral()));					break;				case 6:					formparams.add(new BasicNameValuePair("email", user							.getEmail()));					break;				case 7:					formparams.add(new BasicNameValuePair("gender", user							.getGender()));					break;				case 8:					formparams.add(new BasicNameValuePair("birthday", user							.getBirthday()));					break;				case 9:					formparams.add(new BasicNameValuePair("type", user							.getUserType()));					break;				default:					break;				}				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					try {						dataJson = new JSONObject(jsonString);						String status = dataJson.get("status").toString();						// JSONArray data = dataJson.getJSONArray("data");						if ("0".equals(status)) {							return R.string.success;						} else {							return R.string.fail;						}					} catch (JSONException e) {						e.printStackTrace();					}				} catch (UnsupportedEncodingException e) {					e.printStackTrace();				} catch (ClientProtocolException e) {					e.printStackTrace();				} catch (IOException e) {					e.printStackTrace();				}				return 0;			}			protected void onPostExecute(Integer result) {				switch (result) {				case R.string.success:					if (call != null)						call.onSuccess();					break;				case R.string.fail:					if (call != null)						call.onFailed("fail");					break;				default:					break;				}			};		}.execute();	}	/**	 * 用户密码重置	 * */	public void updatePassword(final User user, final Handler handler) {		final String url = Constants.SERVER_URL				+ Constants.ACTION_UPDATE_PASSWORD;		new Thread() {			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("loginId", user						.getMobile()));				formparams.add(new BasicNameValuePair("password", user						.getPassword()));				formparams.add(new BasicNameValuePair("pwLevel", user						.getPwLevel()));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					try {						dataJson = new JSONObject(jsonString);						String status = dataJson.get("status").toString();						// JSONArray data = dataJson.getJSONArray("data");						if ("0".equals(status)) {							handler.sendEmptyMessage(Constants.MODIFY_PASSWORD_OK);							// return R.string.success;						} else {							handler.sendEmptyMessage(Constants.MODIFY_PASSWORD_FAIL);							// return R.string.fail;						}					} catch (JSONException e) {						// TODO Auto-generated catch block						e.printStackTrace();					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}.start();	}	/**	 * 获取七牛token	 * */	public void getToken(final Handler handler, final FileModel model,			final Context context) {		final String url = Constants.SERVER_URL + Constants.QINIU_GET_TOKEN;		new Thread(new Runnable() {			@Override			public void run() {				Looper.prepare();				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					JSONObject dataJson;					dataJson = new JSONObject(jsonString);					String status = dataJson.get("status").toString();					Log.d("Opencv:LoadObjresult", status);					if (status.equals("0")) {						String data = dataJson.get("data").toString();						Log.d("Opencv:LoadObjresult", data);						Message msg = Message.obtain();						model.token = data;						msg.obj = model;						msg.what = Constants.GET_TOKEN_SUCEESS;						handler.sendMessage(msg);					} else {						handler.sendEmptyMessage(Constants.GET_TOKEN_FAILED);					}				} catch (Exception e) {					handler.sendEmptyMessage(Constants.GET_TOKEN_FAILED);				}				Looper.loop();			}		}).start();	}	/**	 * 上传文件key	 * */	public void qiniuSaveFile(final int fileSize, final String key,			final String type, final String fileType) {		final String url = Constants.SERVER_URL				+ Constants.ACTION_QINIU_SAVE_FILE;		new Thread(new Runnable() {			@Override			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("uuid", App.uuid));				formparams.add(new BasicNameValuePair("key", key));				formparams.add(new BasicNameValuePair("size", fileSize + ""));				formparams.add(new BasicNameValuePair("pictureType", fileType));				if (type.equals(App.mContext.getString(R.string.sub_body_recg))) {					formparams.add(new BasicNameValuePair("type", "01"));				} else if (type.equals(App.mContext.getString(R.string.sub_dys))) {					formparams.add(new BasicNameValuePair("type", "02"));				} else if (type.equals(App.mContext						.getString(R.string.sub_moved))) {					formparams.add(new BasicNameValuePair("type", "03"));				}				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("qiniu", jsonString);					JSONObject dataJson;					try {						dataJson = new JSONObject(jsonString);						System.out.println(dataJson.getInt("status"));						// String status = dataJson.get("status").toString();						// JSONArray data = dataJson.getJSONArray("data");					} catch (JSONException e) {						// TODO Auto-generated catch block						e.printStackTrace();					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}).start();	}	/**	 * 查询忠机设置信息	 * */	public void queryCollectionTerminal(final Device device,	final Handler handler) {		final String url = Constants.SERVER_URL				+ Constants.ACTION_QUERY_DIVICE_SET;		new Thread(new Runnable() {			@Override			public void run() {				Looper.prepare();				// TODO Auto-generated method stub				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("memberId", device						.getMemberId()));				formparams.add(new BasicNameValuePair("uuid", device.getUuid()));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					SetResult setResult = JSON.parseObject(jsonString,							SetResult.class);					if (0 == setResult.status) {						Message msg = Message.obtain();						msg.what = Constants.QUERY_SUB_SET_SUCCESS;						msg.obj = setResult.data;						handler.sendMessage(msg);					} else {						handler.sendEmptyMessage(Constants.QUERY_SUB_SET_FAILED);					}				} catch (Exception e) {					handler.sendEmptyMessage(Constants.QUERY_SUB_SET_FAILED);				}				Looper.loop();			}		}).start();	}	/**	 * 设置忠机设置信息	 * */	public void setCollectionTerminal(final Device device, final Handler handler) {		final String url = Constants.SERVER_URL				+ Constants.ACTION_INSERT_DIVICE_SET;		new Thread(new Runnable() {			@Override			public void run() {				Looper.prepare();				// TODO Auto-generated method stub				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("uuid", device.getUuid()));				formparams.add(new BasicNameValuePair("id", device						.getDiviceId()));				formparams.add(new BasicNameValuePair("startTWhite", device						.getStartTWhite()));				formparams.add(new BasicNameValuePair("endTWhite", device						.getEndTWhite()));				formparams.add(new BasicNameValuePair("deterrenceVWhite",						device.getDeterrenceVWhite()));				String alarmWhite = device.getLarmWhite();				Log.d("startTWhite", device.getStartTWhite());				Log.d("endTWhite", device.getEndTWhite());				Log.d("startTNight", device.getStartTNight());				Log.d("endTNight", device.getEndTNight());				if (alarmWhite.equals(App.mContext						.getString(R.string.sub_take_one))) {					alarmWhite = "01";				} else if (alarmWhite.equals(App.mContext						.getString(R.string.sub_take_three))) {					alarmWhite = "02";				} else if (alarmWhite.equals(App.mContext						.getString(R.string.sub_take_video))) {					alarmWhite = "03";				}				formparams.add(new BasicNameValuePair("larmWhite", alarmWhite));				formparams.add(new BasicNameValuePair("startTNight", device						.getStartTNight()));				formparams.add(new BasicNameValuePair("endTNight", device						.getEndTNight()));				formparams.add(new BasicNameValuePair("deterrenceVNight",						device.getDeterrenceVNight()));				String alarmNight = device.getLarmNight();				if (alarmNight.equals(App.mContext						.getString(R.string.sub_take_one))) {					alarmNight = "01";				} else if (alarmNight.equals(App.mContext						.getString(R.string.sub_take_three))) {					alarmNight = "02";				} else if (alarmNight.equals(App.mContext						.getString(R.string.sub_take_video))) {					alarmNight = "03";				}				formparams.add(new BasicNameValuePair("larmNight", alarmNight));				formparams.add(new BasicNameValuePair("weekNight", device						.getWeekNight()));				formparams.add(new BasicNameValuePair("weekWhite", device						.getWeekWhite()));				formparams.add(new BasicNameValuePair("humanR", device						.isHumanR() ? "T" : "F"));				formparams.add(new BasicNameValuePair("motionD", device						.isMotionD() ? "T" : "F"));				formparams.add(new BasicNameValuePair("flashlight", device						.isFlashlight() ? "T" : "F"));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					System.out.println(status);					if (0 == status) {						handler.sendEmptyMessage(Constants.SET_SUB_SET_SUCCESS);					} else {						handler.sendEmptyMessage(Constants.SET_SUB_SET_FAILED);					}				} catch (Exception e) {					e.printStackTrace();					handler.sendEmptyMessage(Constants.SET_SUB_SET_FAILED);				}				Looper.loop();			}		}).start();	}	/**	 * get news	 * */	public void getNewsMore(final Context con, final Handler handler,			final String time) {		final String url = Constants.SERVER_URL + Constants.GET_NEWS;// GET_NEWS_DETAIL;GET_NEWS_MORE		Log.d("url", url);		new Thread() {			public void run() {				try {					HttpClient httpClient = HttpClientFactory.getFactory()							.getHttpClient();					HttpPost httpPost = new HttpPost(url);					List<NameValuePair> formparams = new ArrayList<NameValuePair>();					UrlEncodedFormEntity entity = new UrlEncodedFormEntity(							formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					dataJson = new JSONObject(jsonString);					String status = dataJson.get("status").toString();					if (!"0".equals(status)) {						if (null != handler)							handler.sendEmptyMessage(Constants.GET_NEWS_FAIL);						return;					}					JSONArray data = null;					try {						data = dataJson.getJSONArray("data");					} catch (Exception e) {						if (null != handler)							handler.sendEmptyMessage(Constants.GET_NEWS_SUCESS);						return;					}					if (data == null) {						return;					}//					JSONArray data = dataJson.getJSONArray("data");										int lenth = data.length();					Log.e("data.length()", lenth + "==");					for (int i = 0; i < lenth; i++) {						int id = data.getJSONObject(i).getInt("id");						String title = data.getJSONObject(i).get("title")								.toString();						String content = data.getJSONObject(i).get("content")								.toString();						String webUrl = data.getJSONObject(i).get("url")								.toString();						String submitTime = data.getJSONObject(i).get("published")								.toString();						Log.e("submitTime", submitTime + "----");						String pictureUrl = data.getJSONObject(i)								.get("picture").toString();						NewsInfo newsInfo = new NewsInfo();						newsInfo.newsId = id;						newsInfo.title = title;						newsInfo.content = content;						newsInfo.webUrl = webUrl;						newsInfo.submitTime = submitTime;						newsInfo.pictureUrl = pictureUrl;						SqliteOperation sqlOperation = new SqliteOperation(con,								AnjiaSQLiteOpenHelper.dbName,								AnjiaSQLiteOpenHelper.version);						sqlOperation.newsInsert(newsInfo);					}					if (null != handler) {						Message msg = Message.obtain();						msg.what = Constants.GET_NEWS_SUCESS;						msg.arg1 = lenth;						handler.sendMessage(msg);					}				} catch (Exception e) {					e.printStackTrace();					if (null != handler)						handler.sendEmptyMessage(Constants.GET_NEWS_FAIL);				}			};		}.start();	}	/**	 * get news	 * */	public void getHelp(final Context con, final Handler handler) {		final String url = Constants.SERVER_URL + Constants.GET_HELP;// GET_NEWS_DETAIL;GET_NEWS_MORE		Log.d("url", url);		helpList.clear();		new Thread() {			public void run() {				try {					HttpClient httpClient = HttpClientFactory.getFactory()							.getHttpClient();					HttpPost httpPost = new HttpPost(url);					Log.d("url02", url);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					try {						dataJson = new JSONObject(jsonString);						String status = dataJson.get("status").toString();						if (!"0".equals(status)) {							if (null != handler)								handler.sendEmptyMessage(Constants.GET_NEWS_FAIL);							return;						}						JSONArray data = dataJson.getJSONArray("data");						int lenth = data.length();						for (int i = 0; i < lenth; i++) {							String id = data.getJSONObject(i).get("id")									.toString();							String title = data.getJSONObject(i).get("title")									.toString();							String webUrl = data.getJSONObject(i).get("url")									.toString();							// String submitTime = data.getJSONObject(i)							// .get("publishedc").toString();							HelpInfo helpInfo = new HelpInfo();							helpInfo.id = id;							helpInfo.title = title;							helpInfo.webUrl = webUrl;							// helpInfo.submitTime = submitTime;							helpList.add(helpInfo); // 获取资讯信息						}						if (helpList.size() != 0) {							if (null != handler)								handler.sendEmptyMessage(Constants.GET_HELP_SUCESS);						} else {							if (null != handler)								handler.sendEmptyMessage(Constants.GET_HELP_FAIL);						}					} catch (JSONException e) {						// TODO Auto-generated catch block						e.printStackTrace();					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			};		}.start();	}	/**	 * 心跳	 * 	 * */	public int sendAlive() {		int status = -1;		final String url = Constants.SERVER_URL + Constants.ACTION_ALIVE;		HttpClient httpClient = HttpClientFactory.getFactory().getHttpClient();		HttpPost httpPost = new HttpPost(url);		List<NameValuePair> formparams = new ArrayList<NameValuePair>();		formparams.add(new BasicNameValuePair("uuid", App.uuid));		UrlEncodedFormEntity entity;		try {			entity = new UrlEncodedFormEntity(formparams, "UTF-8");			httpPost.setEntity(entity);			HttpResponse httpResponse = httpClient.execute(httpPost);			InputStream is = httpResponse.getEntity().getContent();			String jsonString = Util.convertStreamToString(is);			System.out.println(jsonString);			if ("".equals(jsonString) || "null".equals(jsonString))				return -1;			JSONObject jsonobject = new JSONObject(jsonString);			status = jsonobject.getInt("status");		} catch (ClientProtocolException e) {			// TODO Auto-generated catch block			e.printStackTrace();		} catch (IOException e) {			// TODO Auto-generated catch block			e.printStackTrace();		} catch (JSONException e) {			// TODO Auto-generated catch block			e.printStackTrace();		}		return status;	}	/**	 * get news	 * */	public void getNews(final Handler handler) {		final String url = Constants.SERVER_URL + Constants.GET_NEWS;		new Thread(new Runnable() {			@Override			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					try {						dataJson = new JSONObject(jsonString);						String status = dataJson.get("status").toString();						JSONArray data = dataJson.getJSONArray("data");						if ("0".equals(status)) {							Message msg = Message.obtain();							msg.what = 101;							msg.obj = data;							handler.sendMessage(msg);						} else {						}					} catch (JSONException e) {						// TODO Auto-generated catch block						e.printStackTrace();					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}).start();	}	/**	 * get news	 * */	public void getHelp(final Handler handler) {		final String url = Constants.SERVER_URL + Constants.GET_HELP;		new Thread(new Runnable() {			@Override			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					try {						dataJson = new JSONObject(jsonString);						String status = dataJson.get("status").toString();						JSONArray data = dataJson.getJSONArray("data");						if ("0".equals(status)) {							Message msg = Message.obtain();							msg.what = 101;							msg.obj = data;							handler.sendMessage(msg);						} else {							handler.sendEmptyMessage(Constants.GET_HELP_FAIL);						}					} catch (JSONException e) {						// TODO Auto-generated catch block						e.printStackTrace();					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}).start();	}	/**	 * 获取版本信息,用于版本更新	 * 	 * @author wjh	 * */	public void getVersionInfo(final Handler handler) {		final String url = Constants.SERVER_URL + Constants.GET_VERSION_INFO;		new Thread(new Runnable() {			@Override			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("deviceType", "ANDROID"));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					JSONObject dataJson;					try {						dataJson = new JSONObject(jsonString);						String status = dataJson.get("status").toString();						// String data = dataJson.get("data").toString();						// JSONArray data = dataJson.getJSONArray("data");						if ("0".equals(status)) {							Message msg = Message.obtain();							msg.what = Constants.GET_VERSION_OK;							msg.obj = jsonString;							handler.sendMessage(msg);						} else {						}					} catch (JSONException e) {						// TODO Auto-generated catch block						e.printStackTrace();					}				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}).start();	}	/**	 * 获取报警资源链接	 * 	 * @param model	 * @param handler	 */	public void getAlarmUrl(final FileModel model, final Handler handler) {		final String url = Constants.SERVER_URL + Constants.GET_ALARM_URL;		new Thread(new Runnable() {			@Override			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				// new ----------------				Log.d("alarmid", model.alarmId + "");				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams						.add(new BasicNameValuePair("id", model.alarmId + ""));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);					// JSONObject dataJson;					// dataJson = new JSONObject(jsonString);					QiniuUrl result = new Gson().fromJson(jsonString,							QiniuUrl.class);					if ("0".equals(result.status + "")) {						Message msg = Message.obtain();						msg.what = Constants.GET_URL_SUCCESS;						ResultData data = result.data;						if (data != null) {							String types = data.type;							if (types.equals("PICTURE")) {								model.fileType = ".jpg";							} else if (types.equals("MICRO_VIDEO")) {								model.fileType = ".mp4";							}							model.urlPath = "";							for (int i = 0; i < data.path.length; i++) {								model.urlPath += data.path[i] + ";";							}							model.urlPath = model.urlPath.substring(0,									model.urlPath.length() - 1);							msg.obj = model;							handler.sendMessage(msg);						} else {							handler.sendEmptyMessage(Constants.GET_URL_FAILED);						}					} else {						handler.sendEmptyMessage(Constants.GET_URL_FAILED);					}				} catch (Exception e) {					// TODO Auto-generated catch block					e.printStackTrace();					handler.sendEmptyMessage(Constants.GET_URL_FAILED);				}			}		}).start();	}	/**	 * 松开	 * */	public void up(final String uuid) {		final String url = Constants.SERVER_URL + Constants.ACTION_UP;		new Thread(new Runnable() {			@Override			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				// new ----------------				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("uuid", uuid));				formparams.add(new BasicNameValuePair("memberId",						SharedPrefsUtil.getStringValue(App.mContext,								"memberId", "0")));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}).start();	}	/**	 * 按下	 * */	public void down(final String uuid) {		final String url = Constants.SERVER_URL + Constants.ACTION_DOWN;		new Thread(new Runnable() {			@Override			public void run() {				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				// new ----------------				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("uuid", uuid));				formparams.add(new BasicNameValuePair("memberId",						SharedPrefsUtil.getStringValue(App.mContext,								"memberId", "0")));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.d("jsonString", jsonString);				} catch (UnsupportedEncodingException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (ClientProtocolException e) {					// TODO Auto-generated catch block					e.printStackTrace();				} catch (IOException e) {					// TODO Auto-generated catch block					e.printStackTrace();				}			}		}).start();	}	/**	 * 获取威慑警告语音	 * */	public void getAlarmMusic(final Handler handler) {		final String url = Constants.SERVER_URL + Constants.ALARM_MUSIC;		new Thread(new Runnable() {			@Override			public void run() {				Log.e("url", url);				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.e("jsonString", jsonString);					JSONObject dataJson;					dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					JSONArray data = dataJson.getJSONArray("data");					if (0 == status) {						Message msg = Message.obtain();						msg.what = Constants.GET_ALARM_MUSIC_SUCCESS;						msg.obj = data;						handler.sendMessage(msg);					} else {						handler.sendEmptyMessage(Constants.GET_ALARM_MUSIC_FAIL);					}				} catch (Exception e) {					handler.sendEmptyMessage(Constants.GET_ALARM_MUSIC_FAIL);					e.printStackTrace();				}			}		}).start();	}	/**	 * 获取语音url	 * */	public void getAlarmMusicUrl(final String name, final Handler handler) {		final String url = Constants.SERVER_URL + Constants.ALARM_MUSIC_URL;		new Thread(new Runnable() {			@Override			public void run() {				Log.e("url", url);				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				formparams.add(new BasicNameValuePair("name", name));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.e("jsonString", jsonString);					System.out.println("jsonString=" + jsonString);					JSONObject dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					if (0 == status) {						Message msg = Message.obtain();						msg.what = Constants.GET_ALARM_MUSIC_URL_SUCCESS;						msg.obj = dataJson.getJSONObject("data");						handler.sendMessage(msg);					}				} catch (Exception e) {					e.printStackTrace();				}			}		}).start();	}	/**	 * 获取语音url	 * */	public void getShareStatements(final Handler handler) {		final String url = Constants.SERVER_URL + Constants.SHARE_STATEMENTS;		new Thread(new Runnable() {			@Override			public void run() {				Log.e("url", url);				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.e("jsonString", jsonString);					System.out.println("jsonString=" + jsonString);					JSONObject dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					if (0 == status) {						Message msg = Message.obtain();						msg.what = Constants.GET_SHARED_STATEMENTS_SUCCESS;						msg.obj = dataJson.getString("data");						handler.sendMessage(msg);					}				} catch (Exception e) {					e.printStackTrace();				}			}		}).start();	}	/**	 * 获取语音url	 * */	public void getBanner(final Handler handler, final String type) {		final String url = Constants.SERVER_URL + Constants.GET_BANNER;		new Thread(new Runnable() {			@Override			public void run() {				Log.e("url", url);				HttpClient httpClient = HttpClientFactory.getFactory()						.getHttpClient();				HttpPost httpPost = new HttpPost(url);				List<NameValuePair> formparams = new ArrayList<NameValuePair>();				// formparams.add(new BasicNameValuePair("type", type));				formparams.add(new BasicNameValuePair("show", "true"));				UrlEncodedFormEntity entity;				try {					entity = new UrlEncodedFormEntity(formparams, "UTF-8");					httpPost.setEntity(entity);					HttpResponse httpResponse = httpClient.execute(httpPost);					InputStream is = httpResponse.getEntity().getContent();					String jsonString = Util.convertStreamToString(is);					Log.e("jsonString", jsonString);					System.out.println("jsonString=" + jsonString);					JSONObject dataJson = new JSONObject(jsonString);					int status = dataJson.getInt("status");					if (0 == status) {						Message msg = Message.obtain();						msg.what = Constants.GET_BANNER_SUCCESS;						msg.obj = dataJson.getJSONArray("data");						handler.sendMessage(msg);					} else {						handler.sendEmptyMessage(Constants.GET_BANNER_FAIL);					}				} catch (Exception e) {					e.printStackTrace();					handler.sendEmptyMessage(Constants.GET_BANNER_FAIL);				}			}		}).start();	}}